<%@page import="webshop.Cart"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="database.DBConnector"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="../CSS/frontend.css"/>
        <script type="text/javascript" src="scripts.js"></script>
        <%
            DBConnector dbc = DBConnector.getDBC();
            Cart cart = (Cart) session.getAttribute("CART");
            String id = request.getParameter("pid");
            String quantityS = request.getParameter("quantity");
            if (id != null) {
                int quantity = Integer.parseInt(quantityS);
                cart.changeProduct(id, quantity);
            }
        %>
    </head>
    <body>
        <div id="main">
            <jsp:include page="topBar.jsp"></jsp:include>
            <div id="content">
                <%
                    ResultSet rs = dbc.doQuery("CALL getProducts()");
                    while (rs.next()) {
                        String pid = rs.getString(1);
                        String name = rs.getString(2);
                        String price = rs.getString(3);
                        String description = rs.getString(4);
                %>
                <div id="product" >
                    <% out.print(name);%>  <br>
                    Varernummer: <%out.print(pid);%><br>
                    <%out.print(description);%><br>
                    Pris: <%out.print(price);%><br>
                    <form method="get">
                        <input type="hidden" name="pid" value="<%out.print(pid);%>" />
                        <SELECT name="quantity" style="width: 50px;">
                            <%
                                for (int i = 0; i <= 100; i++) {
                                    out.println("<option>" + i + "</option>");
                                }
                            %>
                        </SELECT>
                        <input type="submit" value="Tilføj til Kurven"/>
                    </form>
                </div>
                <% }%>
                <br>
                <a href="cart.jsp">Se indkøbskurven</a>
                <br>
            </div>
            <jsp:include page="footNote.jsp"></jsp:include>
        </div>
    </body>
</html>
